<template>
    <div class="app-container">
        <div v-if="opt != 'add'">
            <el-descriptions title="">
                <el-descriptions-item label="序号">
                    <el-tag size="medium">{{ obj != null ? obj.index : index }}</el-tag>
                </el-descriptions-item>
            </el-descriptions>
        </div>

        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="项目信息" name="first">
                <el-form :model="form" ref="form" label-width="100px">
                    <el-row style="margin-top:20px">
                        <el-col :span="8">
                            <el-form-item label="项目编号" prop="projectNumber" label-width="110px">
                                <el-input v-model="form.projectNumber" placeholder="请输入项目编号"
                                disabled="true"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="项目名称" prop="projectName" label-width="110px">
                                <el-input v-model="form.projectName" placeholder="请输入项目名称"
                                    disabled="true"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="项目负责人" prop="projectLeader" label-width="110px">
                                <el-input v-model="form.projectLeader" disabled="true"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="执行人" prop="executorName" label-width="110px">
                                <el-input v-model="form.executorName" disabled="true"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="费用" prop="sumAmount" label-width="110px">
                                <el-input v-model="form.sumAmount" disabled="true"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="阶段" prop="stageName" label-width="110px">
                                <el-input v-model="form.stageName" disabled="true"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="启动时间" prop="attackTime" label-width="110px">
                                <el-date-picker clearable :disabled="opt == 'details'" style="width: 293px" v-model="form.attackTime"
                                    type="date" value-format="yyyy-MM-dd" placeholder="请选择启动时间" disabled="true">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="完成时间" prop="completeTime" label-width="110px">
                                <el-date-picker clearable :disabled="opt == 'details'" style="width: 293px" v-model="form.completeTime"
                                    type="date" value-format="yyyy-MM-dd" placeholder="请选择完成时间" disabled="true">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-form-item label="项目阶段" prop="node" label-width="110px">
                        <div class="progress-bar">
                            <ul class="yd-step-content" >
                                <li :class="item.calssCss" v-for="item in approvalProcessProject" :id="item.id">
                                    <em class="yd-step-checkmark"> <i></i></em>
                                    <div class="yd-step-item-bottom"><p>{{item.value}}</p></div>
                                </li>
                            </ul>
                        </div>
                    </el-form-item>
                </el-form>
                <div style="text-align: center;margin-top:20px" >
                <!-- <el-button type="primary" @click="submitOK">保 存</el-button> -->
                    <el-button @click="cancel" v-if="opt != 'details'">关 闭</el-button>
                </div>
            </el-tab-pane>
            <el-tab-pane label="进度信息" name="delivery">
                <el-form label-width="100px">
                    <el-form-item label="项目阶段" prop="node" label-width="110px">
                        <div class="progress-bar">
                            <ul class="yd-step-content" >
                                <li :class="item.calssCss" v-for="item in approvalProcessProject" :id="item.id">
                                    <em class="yd-step-checkmark"> <i></i></em>
                                    <div class="yd-step-item-bottom"><p>{{item.value}}</p></div>
                                </li>
                            </ul>
                        </div>
                    </el-form-item>
                    <el-table  style="margin-top:10px" v-loading="loading" :data="projectInfoList" >
                                <el-table-column label="阶段名称" align="center" prop="stageName" width="280" :show-overflow-tooltip="true"/>
                                <el-table-column label="阶段说明" align="center" prop="stageDesc" width="380" :show-overflow-tooltip="true"/>
                                <el-table-column label="是否完成" align="center" prop="stageStatus" :formatter="isStatus" width="180"/>
                                <el-table-column label="创建人" align="center" prop="creationName" width="180"/>
                                <el-table-column label="创建时间" align="center" prop="creationTime" width="180">
                                    <template slot-scope="scope">
                                        <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
                                    </template>
                                </el-table-column>
                        </el-table>
                    </el-form>
                <div style="text-align: center;margin-top:20px" >
                <!-- <el-button type="primary" @click="submitOK">保 存</el-button> -->
                    <el-button @click="cancel">关 闭</el-button>
                </div>
            </el-tab-pane>
            <el-tab-pane label="评价信息" name="evaluate">
                <el-form :model="formEvaluate" ref="formEvaluate" :rules="rulesProject" label-width="100px">
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="老师评分" prop="teacherRating" label-width="110px">
                                <el-rate v-model="formEvaluate.teacherRating" style="margin-top:10px;width:500px" :disabled="opt == 'tb'||opt == 'details'"></el-rate>
                            </el-form-item>
                        </el-col>
                        <!-- <el-col :span="8">
                            <el-form-item label="服务评分" prop="qualityScore" label-width="110px">
                                <el-rate v-model="qualityScore" style="margin-top:10px"></el-rate>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="服务评分" prop="serviceRating" label-width="110px">
                                <el-rate v-model="serviceRating" style="margin-top:10px"></el-rate>
                            </el-form-item>
                        </el-col> -->
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="质量评分" prop="qualityScore" label-width="110px">
                                <el-rate v-model="formEvaluate.qualityScore" style="margin-top:10px" :disabled="opt == 'tb'||opt == 'details'"></el-rate>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="服务评分" prop="serviceRating" label-width="110px">
                                <el-rate v-model="formEvaluate.serviceRating" style="margin-top:10px" :disabled="opt == 'tb' ||opt == 'details'"></el-rate>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="评价" prop="evaluationDescription" label-width="110px">
                                <el-input v-model="formEvaluate.evaluationDescription"  placeholder="请输入评价"  type="textarea"
                                    :autosize="{ minRows: 3, maxRows: 4 }" :disabled="opt == 'tb'"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="确认说明" prop="confirmationDescription" label-width="110px">
                                <el-input v-model="formEvaluate.confirmationDescription"  placeholder="请输入确认说明"  type="textarea"
                                    :autosize="{ minRows: 3, maxRows: 4 }" :disabled="opt == 'tb'"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-form-item label="交付物" >
                        <file-view :type="fjFileType" :businessId="businessId"
                        :businessCode="businessCode" ></file-view>
                    </el-form-item>
                </el-form>
                <div style="text-align: center;margin-top:20px" v-if="opt!='details'">
                    <el-button type="primary" @click="submitOK" v-show="syncShowOK">确 认</el-button>
                    <el-button type="primary" @click="submitWK" v-show="syncShow">文控中心同步</el-button>
                    <el-button type="primary" @click="submitZZ" v-show="syncShow">荣誉资质同步</el-button>
                    <el-button @click="cancel">关 闭</el-button>
                </div>
                <div style="text-align: center;margin-top:20px" v-if="opt=='details'">
                    <el-button @click="cancel">关 闭</el-button>
                </div>
            </el-tab-pane>
        </el-tabs>
        <!-- 交付物选择界面 -->
        <el-dialog :title="titleFile" :visible.sync="openFile" width="800px" append-to-body>
            <el-row>
                <el-col>
                    <!-- <el-form :model="queryParamsFile" ref="queryParamsFile" size="small" :inline="true"
                        v-show="showSearch" label-width="68px">
                        <el-form-item label="文件名称" prop="fileName">
                            <el-input v-model="queryParamsFile.fileName" placeholder="请输入文件名称" clearable
                                @keyup.enter.native="handleQuery" />
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" size="mini"
                                @click="handleQuery">搜索</el-button>
                            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                        </el-form-item>
                    </el-form> -->
                    <el-table v-loading="loading" ref="table" :data="fileList">

                        <!-- <el-table-column v-show="true" label="合同id" align="center" prop="contractId" width="180"
                            :show-overflow-tooltip="true" /> -->
                        <el-table-column label="序号" type="index" align="center" prop="index"
                            :index="indexMethod"></el-table-column>
                        <el-table-column label="文件名称" align="center" prop="fileName" :show-overflow-tooltip="true" width="200" />
                        <el-table-column label="文件类型" align="center" prop="fileType" width="80" />
                        <el-table-column label="创建人" align="center" prop="organizationName" />
                        <el-table-column label="创建时间" align="center" prop="creationTime" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" fixed="right" width="100" class-name="small-padding fixed-width">
                            <template slot-scope="scope">
                              <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit-outline"
                                @click="saveEvaluate(scope.row,scope.$index + 1)"
                              >同步</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <pagination v-show="total > 0" :total="total" :page.sync="queryParamsFile.pageNum"
                        :limit.sync="queryParamsFile.pageSize" @pagination="getFileList" />
                </el-col>
            </el-row>
            <div slot="footer" class="dialog-footer">
                <!-- <el-button type="primary" @click="saveEvaluate">同 步</el-button> -->
                <el-button @click="cancelFile">关 闭</el-button>
            </div>
        </el-dialog>
        <!-- 交付物选择界面 -->

         <!-- 文控同步界面 -->
        <el-dialog :title="titleFileWK" :visible.sync="openFileWK" width="800px"  append-to-body>
          <el-form ref="formFileWK" :model="formFileWK" :rules="rulesFileWK" label-width="100px" :inline="true">
            <el-row >
              <el-col >
                <el-form-item label="文件名称" prop="fileName">
                  <el-input v-model="formFileWK.fileName" placeholder="请输入文件名称" style="width:250px" maxlength="60" show-word-limit/>
                </el-form-item>
                <el-form-item label="文件柜名称" prop="cabinetId">
                  <treeselect v-model="formFileWK.cabinetId" :readonly="true" :options="optionData"  :flat="true"
                  :show-count="true" placeholder="请选择文件柜名称" style="width:250px" />
<!--                  :normalizer="normalizer" 禁用父节点-->
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="文件编号" prop="documentNumber">
                  <el-input v-model="formFileWK.documentNumber" placeholder="请输入文件编号" style="width:250px"/>
                </el-form-item>
                <el-form-item label="建立时间" prop="establishmentTime">
                  <el-input  v-model="formFileWK.establishmentTime" style="width:250px" :disabled="true"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="建立人" prop="establishedName">
                  <el-input v-model="formFileWK.establishedName" style="width:250px" :disabled="true"/>
                </el-form-item>
                <el-form-item label="生效时间" prop="effectiveTime">
                  <el-date-picker clearable
                    v-model="formFileWK.effectiveTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择生效时间" style="width:250px">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="版本" prop="version">
                  <el-input v-model="formFileWK.version" placeholder="请输入版本" style="width:250px"/>
                </el-form-item>
                <el-form-item label="状态" prop="state">
                  <el-select v-model="formFileWK.state" style="width: 250px" placeholder="请选择状态">
                    <el-option v-for="dict in dict.type.file_status" :key="dict.value"
                            :label="dict.label" :value="dict.value"></el-option>
                </el-select>
                </el-form-item>
              </el-col>
            </el-row>

          </el-form>
          <div style="text-align: right">
            <el-button type="primary" @click="submitFormFileWK">确 定</el-button>
              <el-button @click="cancelFileWK">关 闭</el-button>
          </div>
    </el-dialog>
        <!-- 资质同步 -->
        <!-- 添加或修改荣誉资质信息对话框 -->
    <el-dialog :title="titleFileZZ" :visible.sync="openFileZZ" width="800px" append-to-body>
      <el-form ref="formFileZZ" :model="formFileZZ" :rules="rulesFileZZ" label-width="90px" :inline="true">
        <el-form-item label="发证时间" prop="entryTime" label-width="110px">
          <el-date-picker clearable v-model="formFileZZ.entryTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择发证时间"
                          style="width: 202.5px" class="custom-date-picker" >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预警时间" prop="abutmentTime" label-width="110px">
          <el-date-picker clearable v-model="formFileZZ.abutmentTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择预警时间" style="width: 202.5px"></el-date-picker>
        </el-form-item>
        <el-form-item label="证书名称" prop="name" label-width="110px">
          <el-input v-model="formFileZZ.name" placeholder="请输入证书名称" style="width: 202.5px" maxlength="20" show-word-limit />
        </el-form-item>
        <el-form-item label="证书编号" prop="certificateNo" label-width="110px">
          <el-input v-model="formFileZZ.certificateNo" placeholder="请输入证书编号" style="width: 202.5px" maxlength="25" show-word-limit />
        </el-form-item>
        <el-form-item label="证书类别" prop="type" label-width="110px">
          <el-select v-model="formFileZZ.type" placeholder="请选择证书类别" style="width: 202.5px">
            <el-option v-for="dict in dict.type.certificate_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证书规格" prop="level" label-width="110px">
          <el-select v-model="formFileZZ.level" placeholder="请选择证书规格" style="width: 202.5px">
            <el-option v-for="dict in dict.type.certificate_level" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="服务机构" prop="serviceInstitu" label-width="110px">
          <el-input v-model="formFileZZ.serviceInstitu" placeholder="请输入服务机构" style="width: 202.5px" maxlength="20"
                    show-word-limit />
        </el-form-item>
        <el-form-item label="发证机构" prop="certificateInstitution" label-width="110px">
          <el-input v-model="formFileZZ.certificateInstitution" placeholder="请输入发证机构" style="width: 202.5px"  maxlength="20" show-word-limit/>
        </el-form-item>
        <el-form-item label="证书到期日" prop="issuanceTime" label-width="110px">
          <el-date-picker clearable v-model="formFileZZ.issuanceTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择证书到期日" style="width: 202.5px" @change="getEffectiveTime">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="剩余有效时间" prop="effectiveTime" label-width="110px">
          <el-input v-model="formFileZZ.effectiveTime" placeholder="剩余有效时间" style="width: 202.5px" type="number"
                    pattern="[0-9]*" :min="0" disabled="true"/>
          <span style="margin-left: 5px;">年</span>
        </el-form-item>
        <el-form-item label="网址名称" prop="urlName" label-width="110px">
          <el-select v-model="formFileZZ.urlName" placeholder="请选择状态" style="width: 202.5px">
            <el-option v-for="dict in dict.type.honor_urlname" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态" prop="status" label-width="110px">
          <el-select v-model="formFileZZ.status" placeholder="请选择状态" style="width: 202.5px">
            <el-option v-for="dict in dict.type.honer_status" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预警内容" prop="oneExamineStage" label-width="110px">
          <el-input v-model="formFileZZ.oneExamineStage" placeholder="请输入预警内容"   type="textarea" show-word-limit style="width: 525px"/>
        </el-form-item>
        <el-form-item label="创建时间" prop="creationTime" label-width="110px">
          <el-date-picker clearable v-model="formFileZZ.creationTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择时间" style="width: 202.5px" disabled="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createId" label-width="110px">
          <el-input v-model="formFileZZ.createId" placeholder="请输入创建人" disabled="true" style="width: 202.5px" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormFileZZ">确 定</el-button>
        <el-button @click="cancelFileZZ">关 闭</el-button>
      </div>
    </el-dialog>

    </div>
</template>
<script>
import {getScheduleName } from "@/api/project/projectSchedule";
import {getProjectInfo,updateProjectInfo } from "@/api/project/projectInfo";
import { getSubInfo } from "@/api/project/subInfo";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import FileTree from "@/components/File/index";
import FileView from "@/components/FileView/index"
import { download } from "@/utils/request";
import pdf from 'vue-pdf'
import { id } from "@/api/system/UUID";
import { listFile,queryFile,fileRemove,addFile } from "@/api/system/file";//附件
import { listTypeOther } from "@/api/maintype/type";
import {listSchedule} from "@/api/project/projectSchedule";
import {listType} from "@/api/maintype/type";
import {  listFileTreeInternal,addInternal,listInternal} from "@/api/file/internal";//文控中心 内部文件
import { addEvaluateWK,listEvaluation, getEvaluation, delEvaluation, addEvaluation, updateEvaluation }from "@/api/project/evaluation";
import { listManagement, checkSync, delManagement, addManagement, updateManagement } from "@/api/honor/management";//资质
export default {
    name: "deliveryInfo",
  dicts: ['certificate_type', 'certificate_level', 'honer_status', 'honor_urlname','file_status'],
    components: { FileTree,Treeselect,FileView,pdf },
    props: {
        opt: {
            type: String,
            default: ""
        },
        id: {
            type: String,
            default: ""
        },
        sign: {
            type: String,
            default: ""
        },
        obj: {
            type: Object,
            default: null
        },
        //序号
        index: {
            type: Number,
            default: 0
        }
    },
    data() {
        var teacherRating = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('老师评分不能为空'));
            }
            return callback()
        };
        var qualityScore = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('质量评分不能为空'));
            }
            return callback()
        };

        var serviceRating = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('服务评分不能为空'));
            }
            return callback()
        };
        return {
            openFile:false,
            //文控同步
            optionData: null,
            formFileWK:{

            },
            formFile:{

            },
            openFileWK:false,
            fileList:[],
            // 查询参数
            queryParamsFile: {
              pageNum: 1,
              pageSize: 15,
              businessId: null,
              businessCode: null,
              fileName:null
            },

            //---

            //资质同步
            // 查询参数
            queryParamsFileZZ: {
              pageNum: 1,
              pageSize: 15,
              businessId: null,
              businessCode: null,
              fileName:null
            },
            openFileZZ:false,
            optionsFileZZ:null,
            uploadFile:null,
            //---
            opt: 'add',
            //id: '',
            sign:'',
            uploadFileId:null,//附件id
            obj: null,
            index: null,
            edit: 'edit',
            typeFile:0,
            sumEvaluate:0,
            syncShowOK:true,
            syncShow:false,
            refreshKey: 0,
            //选显卡默认选中
            activeName: 'first',
            fjFileType:2,
            businessId: null,
            businessCode: 'project_delivery',
            //阶段信息-----
            approvalProcessProject:[],
            //-----
            radio:'1',
            typeShow:true,
            readonly: true,
            checkCount:0,
            isShowTab:true,
            UUID: '',
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],

            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 弹出层标题
            title: "",
            honorShow: '0',
            // 是否显示弹出层
            open: false,
            titleFile:"项目交付物",
            titleFileWK:"文控中心同步",
            titleFileZZ:"资质荣誉同步",
            // 查询参数
            queryParamsSchedule: {
                projectId: null,
                state:null
            },
            queryParamsEvaluation: {
                projectId: null,
                state:null
            },

            formEvaluate:{
                evaluationDescription: "系统默认好评",
                confirmationDescription:"已确认",
            },
            formFileZZ:{

            },
            form:{
               projectId:null,
            },

            rulesProject:{
                teacherRating: [
                    { required: true, validator: teacherRating, trigger: "blur" }
                ],
                qualityScore: [
                    { required: true, validator: qualityScore, trigger: "change" }
                ],
                serviceRating: [
                    { required: true, validator: serviceRating, trigger: "change" }
                ],
            },
            rulesFileZZ: {
                status: [
                  { required: true, message: '请选择状态', trigger: 'change' }
                ],
                entryTime: [
                  { required: true, message: '请选择发证时间', trigger: 'change' }
                ],
                abutmentTime: [
                  { required: true, message: '请选择预警时间', trigger: 'change' }
                ],
                name: [
                  { required: true, message: '请输入证书名称', trigger: 'blur' }
                ],
                type: [
                  { required: true, message: '请选择证书类别', trigger: 'change' }
                ],
                level: [
                  { required: true, message: '请选择证书级别', trigger: 'change' }
                ],
                serviceInstitu: [
                  { required: true, message: '请输入服务机构', trigger: 'blur' }
                ],
                certificateInstitution: [
                  { required: true, message: '请输入发证机构', trigger: 'blur' }
                ],
                selectUrl:[
                  { required: true, message: '请输入查询网址', trigger: 'blur' }
                ],
                issuanceTime:[
                  { required: true, message: '请选择证书到期时间', trigger: 'change' }
                ],
                effectiveTime:[
                  { required: true, message: '请输入有效时间', trigger: 'blur' }
                ]
                     // 如果有其他字段需要添加校验规则，请继续在此处添加
            },
            //文控 表单校验
            rulesFileWK: {
              fileName: [
                { required: true, message: "文件名称不能为空", trigger: "blur" },
                { max: 60, message: '文件名称长度不能超过60', trigger: 'blur' }
              ],
              documentNumber: [
                { required: true, message: "文件编号不能为空", trigger: "blur" },
                { max: 50, message: '文件编号不能超过50字', trigger: 'blur' }
              ],
              cabinetId: [
                { required: true, message: "文件柜名称不能为空", trigger: "change" }
              ],
              effectiveTime: [
                { required: true, message: "生效时间不能为空", trigger: "change" }
              ],
              state: [
                { required: true, message: "状态不能为空", trigger: "change" }
              ],
              version: [
                { required: true, message: "版本不能为空", trigger: "blur" },
                //{ max: 50, message: '文件编号不能超过50字', trigger: 'blur' }
              ],
            },
            list:[],
            queryParams: {
                projectId: null,
                stateId: null
            },
            projectInfoList:[],
            guId:'',
            formJD:{},
            stageId:'',
        };
    },
    created() {
        if(this.opt=="tb"){//如果是同步进来把确认按钮隐藏
            this.syncShowOK=false
            this.syncShow=true
        }
        this.listTypeData();
        this.getListEvaluation(this.id);
        this.listFileTreeInternal();
        //this.getList();
        let url = window.location.href;
        // 获取参数部分
        let params = url.split('?')[1];
        this.bId = this.id;
        this.businessId = this.id
        this.handleUpdate(this.id)
        this.listSchedule();
        this.listScheduleName();
        this.getFileList(this.id);
        //this.getId();
        this.listType();
    },
    methods: {
        indexMethod(index) {
            return (this.queryParamsFile.pageNum - 1) * this.queryParamsFile.pageSize + index + 1;
        },
        //获取树节点数据
        listType(){
          listType({typeCode:'honor'}).then(res=>{
            this.optionsFileZZ=res.data;
          })
        },
      listTypeData() {
        // listTypeOther({ typeCode: "enterprise" }).then(res => {
        //   this.optionData = res.data;
        // });
        listTypeOther({ typeCode: "enterprise" }).then(response => {
          this.optionData = response.data;
        });
      },
      // 获取有效时间，通过获取证书到期日 - 当前时间等于多少年的有效时间
      getEffectiveTime() {
        // 证书到期日
        let issuanceTime = new Date(this.formFileZZ.issuanceTime);
        // 获取当前时间
        let currentTime = new Date();
        // 获取当前时间的时间戳
        let currentInstant = currentTime.getTime();
        // 获取证书到期日的时间戳
        let expiryInstant = issuanceTime.getTime();
        // 格式化当前日期为 YYYY-MM-DD 格式
        let currentDate = new Date(currentInstant).toISOString().split('T')[0];
        // 格式化证书到期日期为 YYYY-MM-DD 格式
        let expiryDate = new Date(expiryInstant).toISOString().split('T')[0];
        // 计算剩余年数
        let yearsRemaining = Math.floor((new Date(expiryDate).getTime() - new Date(currentDate).getTime()) / (1000 * 60 * 60 * 24 * 365));
        // 不足一年按 0 年算
        if (yearsRemaining < 1) {
          yearsRemaining = 0;
        }
        // 将剩余年数赋值给表单的有效时间字段
        this.formFileZZ.effectiveTime = yearsRemaining;
      },
        //资质同步 提交按钮
        submitFormFileZZ(){
            this.$refs["formFileZZ"].validate(valid => {
            if (valid) {
              checkSync(this.id).then(response => {
                    if(response.msg!=null && response.code==200){
                        this.$message.error('该文件已同步到荣誉资质，不能重复同步！');
                        console.log(response)
                        return;
                    }else{
                        this.formFileZZ.uploadFile=this.id;
                        addManagement(this.formFileZZ).then(response => {
                            this.$modal.msgSuccess("荣誉资质同步成功");
                            this.openFileZZ = false;
                            //this.getList();
                        });
                        //this.formFile.Id = response.msg

                        //this.formFile.businessId = this.guId
                        //原附件信息
                        this.formFile.fileSize = "2"//文件大小 暂存同步类型 1=文控 2=资质
                        this.formFile.content = this.uploadFile//备注 暂存新内部附件id
                        this.formFile.businessId = this.id
                        this.formFile.businessCode = "honor"
                        this.formFile.id=this.uploadFileId//原附件id
                        //往附件表插入数据
                        addEvaluateWK(this.formFile).then(response => {});
                    }

                }).catch(function(error) {
                    this.$message.error('系统错误,请联系管理员！');
                });

            }
        });
     },
      simpleUUID() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
          var r = Math.random() * 16 | 0,
            v = c == 'x' ? r : (r & 0x3 | 0x8);
          return v.toString(16);
        });
      },
        //文控同步 提交按钮
        submitFormFileWK(){
            this.$refs["formFileWK"].validate(valid => {
            if (valid) {
                listInternal(this.formFileWK).then(response => {
                    if(response.total===200){
                        this.$message.error('该文件已同步到文控中心，不能重复同步！');
                        return;
                    }else{
                        this.formFileWK.internalId = this.simpleUUID();
                        addInternal(this.formFileWK).then(response => {
                            if (response.code == 200){
                              this.$modal.msgSuccess("文控中心同步成功");
                              this.openFileWK = false;
                              //this.formFile.businessId = this.guId
                              //原附件信息
                              this.formFile.fileSize = "1"//文件大小 暂存同步类型 1=文控 2=资质
                              this.formFile.content = this.formFileWK.internalId;//备注 暂存新附件id
                              this.formFile.businessId = this.formFileWK.internalId;
                              this.formFile.businessCode = "project_delivery"
                              this.formFile.newFileName = this.formFileWK.fileName;//新附件 暂存文本输入的文件名称
                              this.formFile.id=this.uploadFileId//原附件id
                              //往文件表插入数据
                              addEvaluateWK(this.formFile).then(response => {});
                            }else {
                                this.$message.error('该文件夹下存在重复数据，请检查！');
                              this.openFileWK = false;
                            }
                            //this.getList();
                        });
                        //this.formFile.Id = response.msg
                    }

                }).catch(function(error) {
                    this.$message.error('系统错误,请联系管理员！');
                });

            }
        });
     },
    // getId() {
    //   id({}).then(response => {
    //     this.guId = response.msg
    //     //this.businessId = response.msg
    //   });
    // },
        //文控同步取消按钮
        cancelFileWK(){
            this.openFileWK = false;
            this.getFileList()
        },
        //资质同步取消按钮
        cancelFileZZ(){
            this.openFileZZ = false;
            this.getFileList()
        },
        //文控同步按钮
        submitWK() {
            this.openFile= true
            this.typeFile = 1
        },
        //资质同步按钮
        submitZZ() {
            this.openFile= true
            this.typeFile=2
        },
        //同步按钮 弹页面
        saveEvaluate(row){
            if(this.typeFile == 1){//代表是文控同步
                this.formFileWK.fileName = row.fileName;//文件名称
                this.formFileWK.establishedName = this.$store.state.user.name;
                this.formFileWK.establishedId = this.$store.state.user.info.userId;
                this.formFileWK.establishmentTime = this.parseTime(new Date(), '{y}-{m}-{d}');
                this.uploadFileId=row.id;
                this.openFileWK = true;
                this.openFile= false
            }else if(this.typeFile == 2){//代表是资质同步
                this.openFileZZ = true;
                this.openFile = false;
                this.formFileZZ.projectId=this.id;
                this.formFileZZ.createId= this.$store.state.user.name;
                this.uploadFileId=row.id;
                this.formFileZZ.creationTime=this.parseTime(new Date(), '{y}-{m}-{d}');
                this.formFileZZ.classificationId='650c44e1-b575-4b62-9d54-1ba9d1e8abb7';
                this.formFileZZ.uploadFile = new Date().getTime();
                this.uploadFile = this.formFileZZ.uploadFile;
            }
        },
        //加载文件柜树
        listFileTreeInternal() {
            // listFileTreeInternal().then(res => {
            //     this.optionData = res.data;
            // })
          listTypeOther({ typeCode: "enterprise" }).then(response => {
            this.optionData = response.data;
          });
        },
        //禁用父节点
        normalizer(node) {
            if (node.children && !node.children.length) {
                delete node.children;
            }
            return {
                id: node.id,
                label: node.label,
                isDisabled: node.parentId == '00000000-0000-0000-0000-000000000000' ? true : false,
                children: node.children

            }
        },
        //查询交付物文件
        getFileList() {
            this.resetEvaluation();
            this.queryParamsFile.businessId = this.id
            this.queryParamsFile.businessCode='project_delivery'
            //this.queryParamsFile.content = 0
            this.loading = true;
            listFile(this.queryParamsFile).then(response => {
              this.fileList = response.rows;
              this.total = response.total;
              this.loading = false;
            });
        },

        handleRefresh() {
            // 点击刷新按钮，改变 refreshKey 的值触发组件的重新渲染
            this.refreshKey++
        },
        //** 查询项目阶段说明 根据项目id*/
        listSchedule() {
            setTimeout(() => {
                this.queryParams.stageId = this.stageId
                    listSchedule(this.queryParams).then(response1 => {

                        this.projectInfoList = response1.rows;
                        this.total = response1.total;
                        this.loading = false;

                    });
            }, 200);
        },
        //** 查询项目阶段名称 根据项目id*/
        listScheduleName(id) {
            //this.approvalProcessProject=[];
            this.queryParamsSchedule.projectId=this.id
            getScheduleName(this.queryParamsSchedule).then(response => {

                this.loading = true;
                this.approvalProcessProject = response.data
                this.stageId = response.data[0].stageId



            });
        },
         //查询评价信息
         getListEvaluation(id) {
            this.resetEvaluation();
            this.queryParamsEvaluation.projectId = id
            setTimeout(() => {
                listEvaluation(this.queryParamsEvaluation).then(response => {
                    if(response.rows.length>0){
                        this.formEvaluate = response.rows[0];
                    }
                });
            }, 150);

        },
        submitOK() {
            this.$refs["formEvaluate"].validate(valid => {
                if (valid) {
                    this.sumEvaluate = this.formEvaluate.teacherRating+this.formEvaluate.qualityScore+this.formEvaluate.serviceRating
                    this.formEvaluate.totalScore = this.sumEvaluate
                    this.formEvaluate.projectId = this.form.projectId
                    this.formEvaluate.projectNumber = this.form.projectNumber
                    this.formEvaluate.projectName = this.form.projectName
                    this.form.state = 4
                    this.$modal.confirm('是否确认项目名称为"' + this.form.projectName + '"的数据信息？').then(function () {}).then(() => {
                        addEvaluation(this.formEvaluate).then(response => {
                            this.$modal.msgSuccess("确认成功");
                            this.syncShow = true;
                            this.syncShowOK = false;
                        });
                        //更改项目状态为4完结
                        updateProjectInfo(this.form).then(response => {});

                }).catch(() => { });

                }
            });
        },
        isStatus(row, column) {
            var status = [];
            if (row.stageStatus == 1) {
                status.push("是");
            }else {
                status.push("否");
            }
                return status.join("");
        },
        handleClick(tab, event) {
            // if(tab.name == 'four') {
            //     this.honorShow = 1
            // }
        },


        resetEvaluation() {
            this.formEvaluation = {
                projectId:null,
                projectNumber:null,
                projectName:null,
                confirmationDescription:null,
                teacherRating:null,
                qualityScore:null,
                serviceRating:null,
                totalScore:null,
                evaluationDescription:null,
            };
            this.resetForm("formEvaluation");
        },
       /** 修改按钮操作 */
       handleUpdate(id) {
            getProjectInfo(id).then(response => {
                this.form = response.data;
            });

        },
        getFile(data) {
            //console.log(JSON.stringify(data))
        },
        // 关闭按钮
        cancel() {
            this.open = false;
            this.reset();
            this.$emit('change');
        },
        cancelFile() {
            this.openFile = false;
            this.reset();
            //this.$emit('change');
        },


        // 表单重置
        reset() {
            this.form = {
                stageDesc: null
            };
            this.resetForm("form");
        },
    }
};
</script>
<style type="text/css">
        /* CSS Document */
        body,div,ul ,li ,p{padding:0; margin: 0;}
        li{ list-style:none}
        body{background: #fff;}
        .progress-bar { width: 60%; height: 50px; position: relative; margin-right:90px;margin-bottom:30px; padding-top:30px;}
        .progress-bar-title{font-size: 16px; color: #333; font-weight: bold;position: absolute; top: 18px; left: 20px;}
        .yd-step-content {
            display: -webkit-box;
            display: -webkit-flex;
            display: -ms-flexbox;
            display: flex;
        }
        .yd-step-item {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            -ms-flex: 1;
            flex: 1;
            position: relative;
        }
        .yd-step-item>em {border-radius: 50%;  position: absolute;  top: 50%; left: 50%; background-color: #fff; border:2px solid #ccc;}
        .yd-step-content .yd-step-item>em { width: 28px; height: 28px; margin-left: -13px; margin-top: -17px; z-index: 1002; cursor: pointer;}
        .yd-step-content .yd-step-item-current>em {border:2px solid #14CE67;}

        .yd-step-content .yd-step-item>em.yd-step-checkmark:after {
            content: "";
            position: absolute;
            top: 4px;
            left: 10px;
            border: 3px solid #ccc;
            border-top: 0;
            border-left: 0;
            -webkit-transform: rotate(45deg);
            transform: rotate(45deg);
            width: 6px;
            height: 12px;
        }
        .yd-step-content .yd-step-item-current>em.yd-step-checkmark:after {
            content: "";
            position: absolute;
            top: 4px;
            left: 10px;
            border: 3px solid #14CE67;
            border-top: 0;
            border-left: 0;
            -webkit-transform: rotate(45deg);
            transform: rotate(45deg);
            width: 6px;
            height: 12px;
        }

        .yd-step-content .yd-step-item:not(:first-child):before { width: 100%; left: -50%; }
        .yd-step-item:not(:first-child):before {
            content: "";
            height: 3px;
            position: absolute;
            top: -3px;
            background-color: #e0e0e0;
        }
        .yd-step-content .yd-step-item-current:before{background-color: #e0e0e0;}

        .yd-step-item-bottom {
            position: absolute;
            left: 0;
            text-align: center;
            white-space: nowrap;
            text-overflow: ellipsis;
            width: 100%;
            padding: 0 4px;
        }
        .yd-step-content .yd-step-item-bottom { top: 24px; color: #a5a5a5; font-size: 16px; text-align: center;}
        .yd-step-item-current .yd-step-item-bottom p {color: #14CE67; font-weight: bold;}

    </style>
</style>
